package com.igbeok.miscellaneous.concurrency.thij;

public class WaitPerson3 extends Thread {
	private Restaurant restaurant;
	private Object obj;
//	private boolean isWaiting = false;

	public WaitPerson3(String name, Restaurant r, Object obj) {
		super(name);
		this.restaurant = r;
		this.obj = obj;
	}

	public void run() {
		while (true) {
			while (restaurant.orders.isEmpty()) {
				synchronized (obj) {
					try {
						System.out.println(this + ": Order没有了, 正在等待Order....");
//						isWaiting = true;
						obj.wait();
						System.out.println(this+": 得到通知");
					} catch (InterruptedException e) {
						throw new RuntimeException(e);
					}
					Order2 order = restaurant.orders.get(0);
					System.out.println(this + ": Waitperson得到了 " + order);
//					isWaiting = false;
					restaurant.orders.remove(order);
				}
			}
		}
	}
}
